/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.factory.web.service;

import com.factory.web.json.Plan;
import com.factory.web.json.SchedulerResult;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import java.util.List;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import org.springframework.stereotype.Service;

/**
 *
 * @author milos
 */
@Service
public class SchedulerService implements SchedulerServiceInterface {

    private Client client;
    private final static String url = "http://localhost:8084/algorithms-factory-server/webresources/factory/schedulerResult/";

    public List<Plan> getPlans(String userId, String passwordHash, String inputId) {
        client = new Client();
        WebResource resource = client.resource(url).path(inputId);
        SchedulerResult response = null;
        try {
            response = resource
                    .header("Name", userId)
                    .header("PasswordHash", passwordHash)
                    .accept(MediaType.APPLICATION_JSON_TYPE)
                    .type(MediaType.TEXT_PLAIN_TYPE)
                    .get(SchedulerResult.class);
        } catch (WebApplicationException ex) {
            System.out.println(ex.getMessage());
        }

        return response.getPlans();

    }
}
